package com.qf.erpb.product.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.qf.erpb.core.vo.PageVO;

import com.qf.erpb.product.param.InventoryParam;

import com.qf.erpb.product.service.XgInventoryService;
import com.qf.erpb.product.dao.XgInventoryMapper;
import com.qf.erpb.product.vo.XgInventory;
import org.jetbrains.annotations.NotNull;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import javax.annotation.Resource;

/**
* @author DELL
* @description 针对表【xg_inventory】的数据库操作Service实现
* @createDate 2023-12-22 11:47:58
*/
@Service
public class XgInventoryServiceImpl extends ServiceImpl<XgInventoryMapper, XgInventory>
    implements XgInventoryService{

    @Resource
    private XgInventoryMapper xgInventoryMapper;
    @Override
    public PageVO<XgInventory> pageInventory(InventoryParam inventoryParam) {

//        // 生成动态查询条件wrapper
//        QueryWrapper<XgInventory> wrapper = getXgInventoryQueryWrapper(inventoryParam);
//        // 生成查询分页对象
//        IPage<XgInventory> page = new Page<>(inventoryParam.getPageNum(), inventoryParam.getPageSize());
//        // 查询结果
//        page = xgInventoryMapper.pageInventory(page, wrapper);
//
//        // 生成返回对象
//        PageVO<XgInventory> vo = new PageVO<>();
//        // 获查询总数
//        vo.setTotal(page.getTotal());
//        // 获取查询结果
//        vo.setDataList(page.getRecords());
//        return vo;

        Page<XgInventory> page = new Page<>(inventoryParam.getPageNum(), inventoryParam.getPageSize());
        QueryWrapper<XgInventory> wrapper = new QueryWrapper<XgInventory>();
// if 判断 模糊查询的
        if (StringUtils.hasLength(inventoryParam.getProductId())){
            wrapper.like("product_id",inventoryParam.getProductId());
        }
        if (StringUtils.hasLength(inventoryParam.getProductName())){
            wrapper.like("product_name",inventoryParam.getProductName());
        }
        page = (Page<XgInventory>) xgInventoryMapper.pageInventory(page,wrapper);
        PageVO<XgInventory> pageVO = new PageVO<>();
        pageVO.setTotal(page.getTotal());
        pageVO.setDataList(page.getRecords());
        return pageVO;
    }

//    @NotNull
//    private static QueryWrapper<XgInventory> getXgInventoryQueryWrapper(InventoryParam inventoryParam) {
//        QueryWrapper<XgInventory> wrapper = new QueryWrapper<>();
//        if (StringUtils.hasLength(inventoryParam.getProductId())){
//            wrapper.like("product_id",inventoryParam.getProductId());
//        }
//        if (StringUtils.hasLength(inventoryParam.getProductName())){
//            wrapper.like("product_name",inventoryParam.getProductName());
//        }
//        return wrapper;
//    }

}




